package com.example.qsindusty.jmm_spline.SearchActiviity;


import com.example.qsindusty.jmm_spline.OrdeFragment.OrderData;
import com.example.qsindusty.jmm_spline.api.ApiManager;
import com.yixin.ystartlibrary.base.BasePresenter;
import com.yixin.ystartlibrary.base.IBaseView;

import io.reactivex.Observer;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.schedulers.Schedulers;

/**
 * Created by Administration on 2018/3/13.
 */

public class SearchPresenter  extends BasePresenter implements  ContarctSearch.Presenter{
    ContarctSearch.View mView ;
    @Override
    public void bindView(IBaseView view) {
            mView = (ContarctSearch.View) view;
    }

    @Override
    public void unbindView() {
            dispose();
    }


    @Override
    public void searchOrder(String token, String row, String page, String key) {
        ApiManager.getInstence().getJmmApi().SearchOrder(token,row,page,key)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<OrderData>() {
                    @Override
                    public void onSubscribe(Disposable d) {
                        mView.showLoading();
                    }

                    @Override
                    public void onNext(OrderData orderData) {
                        if (orderData.getCount()==0)

                        mView.searchnomore(orderData.getMessage().toString());
                        else
                            mView.searchSuccessful(orderData);
                    }

                    @Override
                    public void onError(Throwable e) {
                          mView.closeLoading();
                          mView.searchFailer(e.getMessage().toString());
                    }

                    @Override
                    public void onComplete() {
                         mView.closeLoading();

                    }
                });
    }
}
